/**
 * Copyright (C) 2009-2010, LinkedGeoData team at the MOLE research
 * group at AKSW / University of Leipzig
 *
 * This file is part of LinkedGeoData.
 *
 * LinkedGeoData is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * LinkedGeoData is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */
package org.linkedgeodata.access;

import java.awt.geom.Point2D;
import java.awt.geom.RectangularShape;


import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

public class LGDDAOImpl
	implements ILGDDAO
{
	private IURLBuilder urlBuilder;
	
	public LGDDAOImpl(IURLBuilder urlBuilder)
	{
		this.urlBuilder = urlBuilder;
	}
	
	/**
	 * 
	 * 
	 * @param rect
	 * @param model The model to store the data in. If null, a default model
	 *        will be created.
	 * @return
	 */
	@Override
	public Model getData(RectangularShape rect, Model model)
	{
		return readModel(urlBuilder.getData(rect), model);
	}

	@Override
	public Model getData(Point2D point, double radius, Model model)
	{
		return readModel(urlBuilder.getData(point, radius), model);
	}
	
	private Model readModel(String url, Model result)
	{
		if(result == null) {
			result = ModelFactory.createDefaultModel();
		}
		
		System.out.println("Reading model from: " + url);
		result.read(url);
		
		return result;
	}
}